home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
e
/
kyz_obj.lha
/
test
/
catalog
/
README
< prev
Wrap
Text File
|
1998-09-03
|
2KB
|
60 lines
CATALOG OBJECT
What is localization?
On the Amiga, it's the ability for programs to adapt to the locale in which
they are situated. This includes minor things like how money and time
values are handled, string routines being aware of international
characters, and so on. But the major part of localization is the ability to
appear entirely in the user's preferred language.
How is this done? Well, normally programs use 'strings', like so:
WriteF('What is your name?\nName: ')
ReadStr(stdin, name)
WriteF('Hello \s!\n', name)
The first string is literal, the second is a formatting string. We can
introduce a mechanism to swap these strings for a magic number, which we
can give to a function to return the string itself.
CONST WHAT_IS_YOUR_NAME, HELLO_USER
WriteF(getstr(WHAT_IS_YOUR_NAME))
ReadStr(stdin, name)
WriteF(getstr(HELLO_USER), name)
PROC getstr(id)
SELECT id
CASE WHAT_IS_YOUR_NAME; RETURN 'What is your name?\nName: '
CASE HELLO_USER; RETURN 'Hello \s!\n'
ENDSELECT
ENDPROC
Now we have done that, this getstr() function is free to either return the
original string, or change it for another one. What the full getstr()
function does is use locale.library to look up a 'catalog', if there is one
for the user's preferred language, if the ones built into the program
('default strings') aren't the appropriate language in the first place.
If you have not read the docs to locale.library, the docs of CatComp, or
the docs of FlexCat, then do so now.
You have to remove all strings from your program, and replace them with a
call to a function with a named ID (like HELLO_USER as before), then write
a 'catalog descriptor' (.cd) file with these named IDs and the default
strings for those IDs.
Now, you use a program to generate code from that .cd file, which writes
the getstr() function, the code to define all the ID constants, and stores
all the real strings.
At this point, it is easiest to use the source-generator FlexCat. Make an E
source from your catalog, using the provided 'E.sd' file, then simply
compile it and use it in your program in the same way as the example
'helloworld_test.e'.
If you don't use FlexCat (more fool you), basically all you have to do is
create an instance of catalog_obj, open your catalog with it, and provide a
block of default id/string pairs - see the included autodocs.